package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.entity.Category;
import com.itheima.service.impl.CategoryServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryServiceImpl categoryService;
    //新增菜品
    @PostMapping
    public R<String> add(@RequestBody Category category){
        return categoryService.add (category);
    }
    //分页查询
    @GetMapping("/page")
    public R<Page> page(int page,int pageSize){
        return categoryService.page (page,pageSize);

    }
   //删除
    @DeleteMapping
   public R<String> delete(Long id){
       categoryService.remote (id);
       return R.success("删除成功");
   }
   //修改
    @PutMapping
    public R<String>update(@RequestBody Category category){
        return categoryService.update (category);
    }

    //根据条件查询分类数据
    @GetMapping("/list")
    public R<List<Category>> list(Category category){
       return categoryService.list (category);
    }
}
